package com.gcd.alienandwheel.stage;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.LinearGroup;
import com.gcd.alienandwheel.MyGame;
import com.gcd.alienandwheel.MyUtil;
import com.gcd.alienandwheel.actor.MyButton;

/**
 * This is home stage. Contain main menu.
 * @author Rezan Achmad
 */
public class Home extends MyStage {

    MyButton btnAvoid;
    MyButton btnBattle;
    MyButton btnCredit;
    MyButton btnExit;
    LinearGroup linearGroup;

    public Home(MyGame myGame, float width, float height, boolean stretch) {
        super(myGame, width, height, stretch);
        init();
    }

    private void init() {
        Texture texture;

        // Avoid Button
        texture = new Texture(MyUtil.loadImage("btnAvoid.png"));
        btnAvoid = new MyButton("btnAvoid", texture);
        btnAvoid.clickListener = new Button.ClickListener() {

            @Override
            public void clicked(Button button) {
                System.out.println("Click " + button.name);
                myGame.setStage(new Arena2(myGame, width, height, stretch));
            }
        };

        // Battle Button
        texture = new Texture(MyUtil.loadImage("btnBattle.png"));
        btnBattle = new MyButton("btnBattle", texture);
        btnBattle.clickListener = new Button.ClickListener() {

            @Override
            public void clicked(Button button) {
                System.out.println("Click " + button.name);
            }
        };
        
        // Credit Button
        texture = new Texture(MyUtil.loadImage("btnCredit.png"));
        btnCredit = new MyButton("btnCredit", texture);
        btnCredit.clickListener = new Button.ClickListener() {

            @Override
            public void clicked(Button button) {
                System.out.println("Click " + button.name);
                myGame.setStage(new Credit(myGame, width, height, stretch));
            }
        };

        // Exit Button
        texture = new Texture(MyUtil.loadImage("btnExit.png"));
        btnExit = new MyButton("btnExit", texture);
        btnExit.clickListener = new Button.ClickListener() {

            @Override
            public void clicked(Button button) {
                System.out.println("Click " + button.name);
            }
        };

        // Linear Group
        linearGroup = new LinearGroup("menuGroup", texture.getWidth(), texture.getHeight() * 4, LinearGroup.LinearGroupLayout.Vertical);
        linearGroup.addActor(btnExit);
        linearGroup.addActor(btnCredit);
        linearGroup.addActor(btnBattle);
        linearGroup.addActor(btnAvoid);
        addActor(linearGroup);
        linearGroup.x = this.centerX() - linearGroup.width / 2;
        linearGroup.y = this.centerY() - linearGroup.height / 2;
    }
}
